package run.newbug.jt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import run.newbug.jt.pojo.ItemCat;
import run.newbug.jt.service.ItemCatService;
import run.newbug.jt.vo.SysResult;

@RestController
@RequestMapping("itemCat")
@CrossOrigin
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    @GetMapping("findItemCatList/{level}")
    public SysResult findItemCatList(@PathVariable Integer level){

        return SysResult.succe(itemCatService.getItemCatList2(level));
    }

    @PutMapping("status/{id}/{status}")
    public SysResult updaStatus(@PathVariable Integer id, @PathVariable Boolean status){
        return SysResult.succe(itemCatService.updaStatus(id,status));
    }

    @PostMapping("saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){
        return SysResult.succe(itemCatService.saveItemCat(itemCat));
    }

    @DeleteMapping("deleteItemCat")
    public SysResult deleteItemCat(ItemCat itemCat){
        itemCatService.deleteItemCat(itemCat);
        return SysResult.succe();
    }

    @PutMapping("updateItemCat")
    public SysResult updateItemCat(@RequestBody ItemCat itemCat){
        itemCatService.updateItemCat(itemCat);
        return SysResult.succe();
    }
}
